
var endCurrPage = false, endNextPage = false;
setTimeout(function(){
    var $currPage = $('.start_page'),$nextPage = $('#page1st');
    $currPage.data( 'originalClassList', $currPage.attr( 'class' ) );
    $nextPage.data( 'originalClassList', $nextPage.attr( 'class' ) );
    $currPage.css('visibility','visible').addClass('pt-page-current')
    $nextPage.css('visibility','visible')
    var animEndEventNames = {
        'WebkitAnimation' : 'webkitAnimationEnd',
        'OAnimation' : 'oAnimationEnd',
        'msAnimation' : 'MSAnimationEnd',
        'animation' : 'animationend'
    }
    var animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ];
    console.log('animEndEventName:' + animEndEventName)
    var outClass = 'pt-page-rotateCubeLeftOut pt-page-ontop';
    var inClass = 'pt-page-rotateCubeLeftIn';
    $currPage.addClass( outClass ).on( animEndEventName, function() {
        console.log('$currPage')
        $currPage.off( animEndEventName );
        endCurrPage = true;
        if( endNextPage ) {
            onEndAnimation( $currPage, $nextPage );
        }
    } );
//            $currPage.trigger(animEndEventName)
    $nextPage.addClass( inClass ).on( animEndEventName, function() {
        console.log('$nextPage')
        $nextPage.off( animEndEventName );
        endNextPage = true;
        if( endCurrPage ) {
            onEndAnimation( $currPage, $nextPage );
        }
    } );
//            $nextPage.trigger(animEndEventName)
},0)
function onEndAnimation( $outpage, $inpage ) {
    endCurrPage = false;
    endNextPage = false;
    resetPage( $outpage, $inpage );
}
function resetPage( $outpage, $inpage ) {
    //  $outpage.attr( 'class', $outpage.data( 'originalClassList' ));
    $outpage.attr( 'class', $outpage.data( 'originalClassList' ) ).hide()
    $inpage.attr( 'class', $inpage.data( 'originalClassList' ) + ' pt-page-current')
}
